#include <QDialog>
#include <QListWidget>
#include <QPushButton>

#include "includes/usercollection.h"

#ifndef Q_USERS_DIALOG_H
#define Q_USERS_DIALOG_H

class QWidget;

/**
 * Dialog box for user account control. Allows the user to log in, as well
 * as allowing an administrator to add and remove users.
 *
 * Linked to the master UserCollection object.
 *
 * Signals when the currently-signed-in user has changed and when the
 * user collection has changed (by adding or removing users, for example).
 * @author Ronen
 */
class QUsersDialog : public QDialog {
	Q_OBJECT
        // METHODS //////////////////////////////////////////////////////
public:
        /*
         * Default constructor
         */
	QUsersDialog(QWidget* parent = 0);

        /**
         * Associate this dialog with a UserCollection.
         * (data model)
         * @param UserCollection* uc The master collection of users.
         */
	void setUserCollection(UserCollection* uc);
        // PRIVATE METHODS //////////////////////////////////////////////
private:
        /**
         * Populate list widget with user names.
         */
	void populate();
        /**
         * Refresh user collection and list, and send 'changed' signal.
         */
        void refreshUserCollection();
        // SIGNALS //////////////////////////////////////////////////////
signals:
        /**
         * Signal that current user has changed.
         * @param QString username The name of the newly logged-in user.
         */
        void signIn(const QString& username);
        /**
         * Signal that user collection has been changed through dialog interaction.
         * Could be used to trigger 'save' of the user collection.
         */
        void userCollectionChanged();
        // PRIVATE SLOTS ////////////////////////////////////////////////
private slots:
	// create new user
	void addUser();
	// delete existing user
        void removeUser();
	// change active profile to selected user
        void login();
        // for double
        void login(QModelIndex index);

        // save to test location (for debugging)
        void saveTest();
        // PRIVATE MEMBERS //////////////////////////////////////////////
private:
	// list of users
	QListWidget userList;

	// user collection which is being edited
	UserCollection* userCollection;
};

#endif // Q_USERS_DIALOG_H
